public class Solution {
    public int searchInsert(int[] nums, int target) {
        int left = 0,rigth = nums.length - 1;
        while(left < rigth) {
            int mid = left + (rigth - left) / 2;
            if(nums[mid] < target)  left = mid + 1;
            else rigth = mid;
        }
        if(nums[rigth] < target)    return rigth + 1;
        return rigth;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1,3,5,6};
        int target = 7;
        System.out.println(solution.searchInsert(nums,target));
    }
}
